// function echo<T>(str:T):T{
//     return str
// }

// const str = echo('string');

// const num = echo(123);


// function swap<T,U>(tuple:[T,U]):[U,T]{
//     return [tuple[1],tuple[0]]
// }
// console.log( swap([123,'str']))


// interface IWithLength{
//     length:number
// }

// // 约束传入的泛型参数
// function echoIWithLength<T extends IWithLength>(arg:T):T{
//     return arg;
// }

// console.log(echoIWithLength([1,2,3]))
// console.log(echoIWithLength('123'))
// console.log(echoIWithLength({length:444}))



class Queue<T>{
    private data = []
    push(item :T){
        this.data.push(item);
    }
    pop():T{
        return this.data.shift();
    }
}

const queue = new Queue<number>()

queue.push(1)
queue.push(222)
console.log(queue.pop().toFixed())
console.log(queue.pop().toFixed())

interface KeyPair<T,U>{
    key:T,
    value:U
}

let kp1 :KeyPair<number,string> = {key:1,value:'1111'}
let kp2 :KeyPair<string,number> = {key:'22222',value:22}


let arrTwo:Array<number> = [1,2,3]